<template>
  <div class="nav-wrapper">
    <div class="nav-bag">
      <div class="nav-column">
        <a href="javascript:;" :class="index === clickIndex? 'a-hover': ''" v-for="(item, index) in categoryData" :key="item.id" @click="clickChange(index, item.category_id)">
          {{item.name}}
        </a>
      </div>
    </div>

    <div class="nav-screen">
      <div class="main">
        <el-collapse-transition>
          <div class="box-l" v-show="show2">
            <div class="column">
              <div class="column-l">
                类型：
              </div>
              <div class="column-r">
                <p :class="where.is_tmall === true? 'red-bottom-line': ''" @click="where.is_tmall = !where.is_tmall">天猫商品</p>
                <p :class="where.is_tmall === false? 'red-bottom-line': ''" @click="where.is_tmall = !where.is_tmall">不限</p>
              </div>
            </div>
            <div class="column">
              <div class="column-l">
                优惠券：
              </div>
              <div class="column-r">
                <p :class="where.has_coupon === true? 'red-bottom-line': ''" @click="where.has_coupon = !where.has_coupon">有</p>
                <p :class="where.has_coupon === false? 'red-bottom-line': ''" @click="where.has_coupon = !where.has_coupon">不限</p>
              </div>
            </div>
            <div class="column">
              <div class="column-l">
                折扣价：
              </div>
              <div class="column-r">
                <input type="number" placeholder="¥" v-model="where.start_price"> ~
                <input type="number" placeholder="¥" v-model="where.end_price">
              </div>
            </div>
            <div class="column">
              <div class="column-l">
                综合排序：
              </div>
              <div class="column-r">
                <p :class="where.sort === 'total_sales_des'? 'red-bottom-line': ''" @click="where.sort = 'total_sales_des'">销量</p>
                <p :class="where.sort === 'price_des'? 'red-bottom-line': ''" @click="where.sort = 'price_des'">价格</p>
                <p :class="where.sort === 'tk_total_sales_des'? 'red-bottom-line': ''" @click="where.sort = 'tk_total_sales_des'">推广量</p>
              </div>
            </div>
          </div>
        </el-collapse-transition>
        <div class="box-r">
          <p @click="show2 = !show2">筛选</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { getAllCategory } from '@/api/Category';
  export default {
    name: "v-nav",
    data(){
      return {
        categoryData: [],
        clickIndex: '',
        show2: false,
        where: {
          category_id: '', //类别ID(多个逗号隔开)
          is_tmall: false, //商品筛选-是否天猫商品。true表示属于天猫商品，false或不设置表示不限
          has_coupon: true, //优惠券筛选-是否有优惠券。true表示该商品有优惠券，false或不设置表示不限
          start_price: '', //商品筛选-折扣价范围下限。单位：元
          end_price: '', //商品筛选-折扣价范围上限。单位：元
          need_free_shipment: false, //商品筛选-是否包邮。true表示包邮，false或不设置表示不限
          sort: '', //排序_des（降序），排序_asc（升序），销量（total_sales），淘客佣金比率（tk_rate）， 累计推广量（tk_total_sales），总支出佣金（tk_total_commi），价格（price）
        }
      }
    },
    mounted() {
      getAllCategory().then(res => this.categoryData = res);
    },
    methods: {
      clickChange(index, categoryId){
        this.clickIndex = index
        this.where.category_id = categoryId
      },
    },
    watch:{
      where: {
        handler: function (value) {
          this.$emit('where', value);
        },
        deep: true
      }
    }
  }
</script>

<style scoped>
.nav-wrapper{
  width: 100%;
}
.nav-wrapper .nav-bag{
  width: 100%;
  height: 64px;
  background: linear-gradient(to right,#2c3bde,#d645f8);
}
.nav-wrapper .nav-bag .nav-column{
  margin: auto;
  width: 1200px;
  height: 64px;
  display: flex;
  justify-content: flex-start;
}
.nav-wrapper .nav-bag .nav-column a{
  text-align: center;
  width: 100px;
  height: 26px;
  font-size: 14px;
  text-decoration: none;
  color: white;
  padding: 3px 5px;
  transition: all 0.4s;
  box-sizing: border-box;
  margin-top: 20px;
  /*background:linear-gradient(to right, red, white);*/
  /*-webkit-background-clip:text;*/
  /*color:transparent;*/
}
.nav-wrapper .nav-bag .nav-column .a-hover{
  font-size: 16px;
  transform:rotate(-15deg);
  border-bottom: 2px solid white;
}


.nav-wrapper .nav-screen{
  width: 1200px;
  margin: auto;
}
.nav-wrapper .nav-screen .main{
  margin-top:15px;
  position: relative;
  background: linear-gradient(to right,#2c3bde,#d645f8);
  padding:18px 20px;
  border-radius: 5px;
  border-bottom-right-radius: 17.5px;
  color: white;
}
.nav-wrapper .nav-screen .main .box-r{
  position: absolute;
  top:0px;
  right: 0px;
  width: 35px;
  height: 35px;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
  border-top-right-radius: 5px;
  background: red;
  line-height: 35px;
  text-align: center;
  cursor:pointer;
  -webkit-user-select:none;
  -moz-user-select:none;
  -ms-user-select:none;
  user-select:none;
}

.nav-wrapper .nav-screen .main .box-l .column{
  display: flex;
  justify-content: flex-start;
  user-select:none;
  padding: 3px 3px;
  line-height: 24px;
}
.nav-wrapper .nav-screen .main .box-l .column .column-l{
  width: 70px;
}
.nav-wrapper .nav-screen .main .box-l .column .column-r{
  display: flex;
  justify-content: flex-start;
}
.nav-wrapper .nav-screen .main .box-l .column .column-r p{
  margin-right: 15px;
  cursor:pointer;
}
.nav-wrapper .nav-screen .main .box-l .column .column-r input{
  width: 55px;
  height: 18px;
  border:1px solid #EEEEEE;
  border-radius: 3px;
}
.red-bottom-line{
  border-bottom: 2px solid red;
}

</style>
